Conversation
| #include <stack> | ||
| using namespace std; | ||
|
|
||
| vector<int> dailyTemp(const vecror<inr>& temp){ |
There was a problem hiding this comment.
warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]
| vector<int> dailyTemp(const vecror<inr>& temp){ | |
| vector<int> dailyTemp(const vector<inr>& temp){ |
Additional context
/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here
class vector : protected _Vector_base<_Tp, _Alloc>
^| #include <stack> | ||
| using namespace std; | ||
|
|
||
| vector<int> dailyTemp(const vecror<inr>& temp){ |
There was a problem hiding this comment.
warning: use of undeclared identifier 'inr'; did you mean 'int'? [clang-diagnostic-error]
| vector<int> dailyTemp(const vecror<inr>& temp){ | |
| vector<int> dailyTemp(const vecror<int>& temp){ |
| #include <iostream> | ||
|
|
||
| int findOrderStat(int[] arr, int k) { | ||
| int l= 0, r = arr.length; |
There was a problem hiding this comment.
warning: use of undeclared identifier 'arr' [clang-diagnostic-error]
int l= 0, r = arr.length;
^| int findOrderStat(int[] arr, int k) { | ||
| int l= 0, r = arr.length; | ||
| while (true) { | ||
| int m = partition(arr, l, r); |
There was a problem hiding this comment.
warning: use of undeclared identifier 'arr' [clang-diagnostic-error]
int m = partition(arr, l, r);
^| while (true) { | ||
| int m = partition(arr, l, r); | ||
|
|
||
| if (m == k) { |
There was a problem hiding this comment.
warning: use of undeclared identifier 'k' [clang-diagnostic-error]
if (m == k) {
^| int m = partition(arr, l, r); | ||
|
|
||
| if (m == k) { | ||
| return arr[m]; |
There was a problem hiding this comment.
warning: use of undeclared identifier 'arr' [clang-diagnostic-error]
return arr[m];
^| if (m == k) { | ||
| return arr[m]; | ||
| } | ||
| else if (k < m) { |
There was a problem hiding this comment.
warning: use of undeclared identifier 'k' [clang-diagnostic-error]
else if (k < m) {
^Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
| Node *parent; | ||
|
|
||
| Node(int key, string colour, Node *left_child, Node *right_child, Node *parent = nullptr) | ||
| : key(key), colour(colour), left_child(left_child), right_child(right_child), parent(parent) {} |
There was a problem hiding this comment.
warning: parameter 'colour' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]
task_07/src/red_black_tree.hpp:2:
- #include <vector>
+ #include <utility>
+ #include <vector>| : key(key), colour(colour), left_child(left_child), right_child(right_child), parent(parent) {} | |
| : key(key), colour(std::move(colour)), left_child(left_child), right_child(right_child), parent(parent) {} |
| private: | ||
| struct Node | ||
| { | ||
| bool full; |
There was a problem hiding this comment.
warning: use default member initializer for 'full' [cppcoreguidelines-use-default-member-init]
| bool full; | |
| bool full{true}; |
task_08/src/hash_table.hpp:14:
- Node(T value) : full(true), value(value) {}
+ Node(T value) : , value(value) {}| #include <stack> | ||
| using namespace std; | ||
|
|
||
| static vector<int> dailyTemp(const vecror<inr>& temp){ |
There was a problem hiding this comment.
warning: function 'dailyTemp' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
static vector<int> dailyTemp(const vecror<inr>& temp){
^| #include <stack> | ||
| using namespace std; | ||
|
|
||
| static vector<int> dailyTemp(const vecror<inr>& temp){ |
There was a problem hiding this comment.
warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]
| static vector<int> dailyTemp(const vecror<inr>& temp){ | |
| static vector<int> dailyTemp(const vector<inr>& temp){ |
Additional context
/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here
class vector : protected _Vector_base<_Tp, _Alloc>
^Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
|
||
| using namespace std; | ||
|
|
||
| static vector<pair<int, int>> bFish(const vector<int>& prices, int k){ |
There was a problem hiding this comment.
warning: function 'bFish' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
static vector<pair<int, int>> bFish(const vector<int>& prices, int k){
^| #include <stack> | ||
| using namespace std; | ||
|
|
||
| static vector<int> dailyTemp(const vecror<int>& temp){ |
There was a problem hiding this comment.
warning: function 'dailyTemp' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]
static vector<int> dailyTemp(const vecror<int>& temp){
^| #include <stack> | ||
| using namespace std; | ||
|
|
||
| static vector<int> dailyTemp(const vecror<int>& temp){ |
There was a problem hiding this comment.
warning: no template named 'vecror'; did you mean 'vector'? [clang-diagnostic-error]
| static vector<int> dailyTemp(const vecror<int>& temp){ | |
| static vector<int> dailyTemp(const vector<int>& temp){ |
Additional context
/usr/include/c++/13/bits/stl_vector.h:427: 'vector' declared here
class vector : protected _Vector_base<_Tp, _Alloc>
^| } | ||
| int left = 0; | ||
| int right = n-1; | ||
| while(left!=right) |
There was a problem hiding this comment.
Если не найдётся пара чисел, сумма которых равна c, программа зациклится (while(left!=right)), т.к. выход только через break. Это может привести к бесконечному циклу.
| int right = n-1; | ||
| while(left!=right) | ||
| { | ||
| if (a[left]+a[right]<c) {left+=1; continue;} |
| #include <stack> | ||
| using namespace std; | ||
|
|
||
| static vector<int> dailyTemp(const vecror<int>& temp){ |
There was a problem hiding this comment.
DailyTemp
и вынести в отдельный файл
| @@ -1,3 +1,6 @@ | |||
| #include <iostream> | |||
| #include <vector> | |||
| using namespace std; | |||
There was a problem hiding this comment.
Я не до конца поняла, нужно было её делать или нет, т.к. в исходном файле уже было решение этой задачи
There was a problem hiding this comment.
там реализация наивная и не оптимальная) нужно написать заново не на stack'е
|
|
||
| int main() { return 0; } | ||
| template <typename type_ar> | ||
| int part(type_ar *ar, int l, int r) { |
| } | ||
|
|
||
| template <typename type_arrr> | ||
| void q_sort(type_arrr *arrr, int l, int r) { |
| @@ -1,3 +1,20 @@ | |||
| #include <iostream> | |||
|
|
|||
| int findOrderStat(int[] arr, int k) { | |||
| private: | ||
| struct Node { | ||
| int key; | ||
| string colour; |
There was a problem hiding this comment.
лучше использовать enum
|
|
||
| public: | ||
| Black_Red_Tree() { | ||
| nil = new Node(0, "BLACK", nullptr, nullptr); |
There was a problem hiding this comment.
раз есть new значит должен быть и деструктор с delete
| root = nil; | ||
| } | ||
|
|
||
| void insert(int key); |
There was a problem hiding this comment.
Insert
Delete
and etc.
There was a problem hiding this comment.
Везде, где используется buffer[begin]->value, нет проверки, что buffer[begin] != nullptr. Это приведёт к разыменованию nullptr.
There was a problem hiding this comment.
Увидела ошибку. Спасибо!
|
|
||
| TEST(QuickSortTest, EmptyArray) { | ||
| int arr[] = {}; | ||
| ASSERT_NO_THROW(QuickSort(arr, 0, -1)); |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
int arr[] = {};
^| TEST(QuickSortTest, EmptyArray) { | ||
| int arr[] = {}; | ||
| ASSERT_NO_THROW(QuickSort(arr, 0, -1)); | ||
| } |
There was a problem hiding this comment.
warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
ASSERT_NO_THROW(QuickSort(arr, 0, -1));
^|
|
||
| TEST(QuickSortTest, SingleElement) { | ||
| int arr[] = {42}; | ||
| TestSorting(arr, 1); |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
int arr[] = {42};
^| TEST(QuickSortTest, SingleElement) { | ||
| int arr[] = {42}; | ||
| TestSorting(arr, 1); | ||
| } |
There was a problem hiding this comment.
warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
TestSorting(arr, 1);
^|
|
||
| TEST(QuickSortTest, DuplicateElements) { | ||
| int arr[] = {2, 2, 1, 1, 3, 3}; | ||
| TestSorting(arr, 6); |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
int arr[] = {2, 2, 1, 1, 3, 3};
^| TEST(QuickSortTest, DuplicateElements) { | ||
| int arr[] = {2, 2, 1, 1, 3, 3}; | ||
| TestSorting(arr, 6); | ||
| } |
There was a problem hiding this comment.
warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
TestSorting(arr, 6);
^|
|
||
| TEST(QuickSortTest, FloatArray) { | ||
| float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f}; | ||
| TestSorting(arr, 5); |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f};
^| TEST(QuickSortTest, FloatArray) { | ||
| float arr[] = {1.5f, 0.5f, 2.5f, 1.1f, 3.3f}; | ||
| TestSorting(arr, 5); | ||
| } |
There was a problem hiding this comment.
warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]
TestSorting(arr, 5);
^|
|
||
| // Случай 1: У z нет левого потомка | ||
| if (z->left_child == nil) { | ||
| x = z->right_child; |
There was a problem hiding this comment.
warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]
olour = Colour::Black;
^Additional context
task_07/src/red_black_tree.cpp:251: Calling 'RedBlackTree::Search'
Search(key);
^task_07/src/red_black_tree.cpp:117: Assuming 'current' is not equal to field 'nil'
* current = root;
^task_07/src/red_black_tree.cpp:117: Left side of '&&' is true
* current = root;
^task_07/src/red_black_tree.cpp:117: Assuming 'key' is equal to field 'key'
* current = root;
^task_07/src/red_black_tree.cpp:117: Loop condition is false. Execution continues on line 125
* current = root;
^task_07/src/red_black_tree.cpp:251: Returning from 'RedBlackTree::Search'
Search(key);
^task_07/src/red_black_tree.cpp:251: 'z' is not equal to field 'nil'
Search(key);
^task_07/src/red_black_tree.cpp:251: Taking false branch
Search(key);
^task_07/src/red_black_tree.cpp:256: Assuming field 'left_child' is not equal to field 'nil'
евого потомка
^task_07/src/red_black_tree.cpp:256: Taking false branch
евого потомка
^task_07/src/red_black_tree.cpp:264: Assuming field 'right_child' is equal to field 'nil'
(z->right_child == nil) {
^task_07/src/red_black_tree.cpp:263: Taking true branch
потомка
^task_07/src/red_black_tree.cpp:266: Calling 'RedBlackTree::Transplant'
Transplant(z, z->left_child);
^task_07/src/red_black_tree.cpp:165: Assuming field 'parent' is not equal to field 'nil'
(u->parent == nil) {
^task_07/src/red_black_tree.cpp:164: Taking false branch
ansplant(Node* u, Node* v) {
^task_07/src/red_black_tree.cpp:168: Assuming 'u' is not equal to field 'left_child'
u == u->parent->left_child) {
^task_07/src/red_black_tree.cpp:167: Taking false branch
e if (u == u->parent->left_child) {
^task_07/src/red_black_tree.cpp:266: Returning from 'RedBlackTree::Transplant'
Transplant(z, z->left_child);
^task_07/src/red_black_tree.cpp:-1: Memory is released
child);
^task_07/src/red_black_tree.cpp:-1: Assuming 'yOriginalColor' is equal to Black
child);
^task_07/src/red_black_tree.cpp:-1: Taking true branch
child);
^task_07/src/red_black_tree.cpp:-1: Calling 'RedBlackTree::FixDel'
child);
^task_07/src/red_black_tree.cpp:181: Assuming 'x' is not equal to field 'root'
Tree::FixDel(Node* x) {
^task_07/src/red_black_tree.cpp:181: Left side of '&&' is true
Tree::FixDel(Node* x) {
^task_07/src/red_black_tree.cpp:182: Assuming field 'colour' is equal to Black
& x->colour == Colour::Black) {
^task_07/src/red_black_tree.cpp:181: Loop condition is true. Entering loop body
Tree::FixDel(Node* x) {
^task_07/src/red_black_tree.cpp:183: Assuming 'x' is equal to field 'left_child'
if (x == x->parent->left_child) {
^task_07/src/red_black_tree.cpp:183: Taking true branch
if (x == x->parent->left_child) {
^task_07/src/red_black_tree.cpp:186: Field 'colour' is not equal to Red
^task_07/src/red_black_tree.cpp:186: Taking false branch
^task_07/src/red_black_tree.cpp:193: Assuming field 'colour' is not equal to Black
if (w->left_child->colour == Colour::Black && w->right_child->colour == Colour::Black) {
^task_07/src/red_black_tree.cpp:194: Left side of '&&' is false
>colour == Colour::Black && w->right_child->colour == Colour::Black) {
^task_07/src/red_black_tree.cpp:199: Assuming field 'colour' is not equal to Black
if (w->right_child->colour == Colour::Black) {
^task_07/src/red_black_tree.cpp:199: Taking false branch
if (w->right_child->colour == Colour::Black) {
^task_07/src/red_black_tree.cpp:181: 'x' is equal to field 'root'
Tree::FixDel(Node* x) {
^task_07/src/red_black_tree.cpp:181: Left side of '&&' is false
Tree::FixDel(Node* x) {
^task_07/src/red_black_tree.cpp:248: Use of memory after it is freed
olour = Colour::Black;
^| @@ -0,0 +1,65 @@ | |||
| #pragma once | |||
| enum class Colour{ Red = 0, Black }; | |||
There was a problem hiding this comment.
warning: enum 'Colour' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]
enum class Colour{ Red = 0, Black };
^|
|
||
| public: | ||
| RedBlackTree() { | ||
| nil = new Node(0, Colour::Black, nullptr, nullptr); |
There was a problem hiding this comment.
warning: 'nil' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
task_07/src/red_black_tree.hpp:41:
- RedBlackTree() {
- nil = new Node(0, Colour::Black, nullptr, nullptr);
+ RedBlackTree() : nil(new Node(0, Colour::Black, nullptr, nullptr)) {
+ |
|
||
| class RedBlackTreeTest : public ::testing::Test { | ||
| protected: | ||
| RedBlackTree tree; |
There was a problem hiding this comment.
warning: member variable 'tree' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]
RedBlackTree tree;
^| #include <gtest/gtest.h> | ||
| #include "hash_table.hpp" | ||
|
|
||
| size_t simple_begin_hash(int value) { |
There was a problem hiding this comment.
warning: function 'simple_begin_hash' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| size_t simple_begin_hash(int value) { | |
| static size_t simple_begin_hash(int value) { |
| TEST(TopologySort, Simple) { | ||
| ASSERT_EQ(1, 1); // Stack [] | ||
| size_t simple_step_hash(int value) { | ||
| return value + 1; |
There was a problem hiding this comment.
warning: function 'simple_step_hash' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| size_t simple_step_hash(int value) { | |
| static size_t simple_step_hash(int value) { |
| } | ||
|
|
||
| class HashTableTest : public ::testing::Test { | ||
| protected: |
There was a problem hiding this comment.
warning: constructor does not initialize these fields: table [cppcoreguidelines-pro-type-member-init]
task_08/src/test.cpp:21:
- Hashtable<int>* table;
+ Hashtable<int>* table{};| } | ||
|
|
||
| Hashtable<int>* table; | ||
| }; |
There was a problem hiding this comment.
warning: member variable 'table' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]
Hashtable<int>* table;
^There was a problem hiding this comment.
удали из домашки плиз теорию
| #include <vector> | ||
| using namespace std; | ||
|
|
||
| struct Result |
There was a problem hiding this comment.
норм решение, но лучше обернуть все в std::optional, станет красивее
| int left = 0, right = 0; | ||
| }; | ||
|
|
||
| inline Result Solve(int n, int c, const vector<int>& a) |
There was a problem hiding this comment.
давай не a а array и другие имена тоже
n тут не нужна) просто сделай array.size()
There was a problem hiding this comment.
std::optional<Result> SumOfTwo(int sum_of_two, const vector<int>& array) будет выглдеть намного лучше)
There was a problem hiding this comment.
и лучше сделай еще один файл cpp и туда реализацию перекинь) и имя файлу лучше придумать по лучше
|
|
||
| using namespace std; | ||
|
|
||
| inline vector<pair<int, int>> BFish(const vector<int>& prices, int k) { |
There was a problem hiding this comment.
а зачем везде inline использовать для функций?
There was a problem hiding this comment.
и тут лучше как в первой задаче сделать структуру, а не пару
| #include <cmath> | ||
| using namespace std; | ||
|
|
||
| template <typename type_ar> |
There was a problem hiding this comment.
давай не type_ar а ArrayType или что то подобное, будет красивее, а когда красивее я довольнее и значит оценка выше)
| } | ||
|
|
||
| template <typename type_arrr> | ||
| void QuickSort(type_arrr *arrr, int l, int r) { |
There was a problem hiding this comment.
не очень хорошие названия параметров, непонятно что они означают
There was a problem hiding this comment.
ну и если хочешь ещё улучшить то лучше не передавать указатель на массив, а считать что это контейнер с произвольным доступом)
в идеале вот так:
template <typename Container>
concept SortableContainer = requires(Container a, int i, int j) {
{ a[i] } -> std::convertible_to<typename Container::value_type>;
{ a.size() } -> std::convertible_to<std::size_t>;
{ a[i] < a[j] } -> std::convertible_to<bool>;
{ a[i] > a[j] } -> std::convertible_to<bool>;
{ swap(a[i], a[j]) };
};
template <SortableContainer Container>
void QuickSort(Container& array)|
|
||
| using namespace std; | ||
|
|
||
| inline int Partition(vector<int> ar, int l, int r) { |
There was a problem hiding this comment.
довольно странно что тесты проходят, ты тут swap(ar[i++], ar[j--]); делаешь, и меняешь порядок элементов, но в копии ar тут похоже нужно передавать по ссылке а не по значению, это ускорит и будет правильнее работать
| throw out_of_range("Invalid k value or empty array"); | ||
| } | ||
|
|
||
| int l = 0, r = arr.size(); |
There was a problem hiding this comment.
давай 1 строка одно объявление
и тут у тебя r = size() и в Partition будешь вылезать на 1 элемент из вектора, нужно size() - 1
| Node *y = nil; | ||
| Node *x = root; | ||
|
|
||
| while (x != nil) { |
| }; | ||
|
|
||
| Node *root; | ||
| Node *nil; |
There was a problem hiding this comment.
довольно странное решение, лучше использовать nullptr
| @@ -0,0 +1,65 @@ | |||
| #pragma once | |||
| enum class Colour{ Red = 0, Black }; | |||
There was a problem hiding this comment.
можно перенести внутрь Node, что бы не светить наружу реализацию
| std::function<size_t(T)> beginHash, stepHash; | ||
|
|
||
| public: | ||
| Hashtable(std::function<size_t(T)> beginHash, std::function<size_t(T)> stepHash) : beginHash(beginHash), stepHash(stepHash) {}; |
There was a problem hiding this comment.
хорошо бы и деструктор завести, раз выделяем память через new в векторе, а то будет утечка
| #include <iostream> | ||
|
|
||
| int main() { return 0; } | ||
| using namespace std; |
There was a problem hiding this comment.
давай удалим раз уж закоментировали)
No description provided.